﻿// <copyright file="InteractionManager.cs" company="Ucaya">
// </copyright>
// <author>Ucaya</author>

namespace KinectExtensions.Services
{
    #region

    using System;
    using System.ComponentModel;
    using System.ComponentModel.Composition;
    using System.Linq.Expressions;

    using KinectExtensions.Nui;

    #endregion

    /// <summary>
    ///   TODO: Update summary.
    /// </summary>
    [Export]
    public class InteractionManager : INotifyPropertyChanged
    {
        #region Constants and Fields

        /// <summary>
        ///   The current interaction mode.
        /// </summary>
        private Interactions currentInteractionMode = Interactions.Mouse;

        #endregion

        #region Public Events

        /// <summary>
        ///   The current interaction mode changed.
        /// </summary>
        public event EventHandler CurrentInteractionModeChanged;

        /// <summary>
        ///   The property changed.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region Public Properties

        /// <summary>
        ///   Gets or sets CurrentInteractionMode.
        /// </summary>
        public Interactions CurrentInteractionMode
        {
            get
            {
                return this.currentInteractionMode;
            }

            set
            {
                if (this.currentInteractionMode != value)
                {
                    this.currentInteractionMode = value;
                    this.RaisePropertyChanged(n => n.CurrentInteractionMode);
                    this.OnCurrentInteractionModeChanged();
                }
            }
        }

        #endregion

        #region Methods

        /// <summary>
        ///   The on current interaction mode changed.
        /// </summary>
        protected virtual void OnCurrentInteractionModeChanged()
        {
            if (this.CurrentInteractionModeChanged != null)
            {
                this.CurrentInteractionModeChanged(this, EventArgs.Empty);
            }
        }

        /// <summary>
        ///   The raise property changed.
        /// </summary>
        /// <param name = "expression">
        ///   The expression.
        /// </param>
        /// <typeparam name = "TProperty">
        /// </typeparam>
        protected void RaisePropertyChanged<TProperty>(Expression<Func<InteractionManager, TProperty>> expression)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(this.GetPropertyName(expression)));
            }
        }

        #endregion
    }
}